home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
C
/
regintes.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-30
|
5KB
|
172 lines
/* region test program v1.0 */
/****************************************************************
* *
* Copyright 1985, Commodore Amiga Inc. All rights reserved. *
* No part of this program may be reproduced, transmitted, *
* transcribed, stored in retrieval system, or translated into *
* any language or computer language, in any form or by any *
* means, electronic, mechanical, magnetic, optical, chemical, *
* manual or otherwise, without the prior written permission of *
* Commodore Amiga Incorporated, 983 University Ave, #D *
* Los Gatos, CA 95030 *
* *
****************************************************************/
/* SIMPLE REGIONS EXAMPLE.... DRAW BEHIND A FENCE */
#include <exec/types.h>
#include <graphics/gfx.h>
#include <hardware/dmabits.h>
#include <hardware/custom.h>
#include <graphics/gfxmacros.h>
#include <graphics/rastport.h>
#include <graphics/view.h>
#include <exec/exec.h>
#include <graphics/layers.h>
#include <graphics/clip.h>
#define FLAGS LAYERSIMPLE
extern struct Layer *CreateUpfrontLayer();
#define DEPTH 2
#define WIDTH 320
#define HEIGHT 200
#define NOT_ENOUGH_MEMORY -1000
#define FOREVER for(;;)
struct View v;
struct ViewPort vp;
struct ColorMap *cm;
struct RasInfo ri;
struct BitMap b;
struct RastPort *rp; /* one rastport for one layer */
short i,j,k,n;
struct ColorMap *GetColorMap();
struct GfxBase *GfxBase;
USHORT colortable[] = { 0x000, 0xf00, 0x0f0, 0x00f };
/* black, red, green, blue */
UBYTE *displaymem;
UWORD *colorpalette;
struct LayersBase *LayersBase;
struct Layer_Info li;
struct Layer *layer; /* one layer pointer */
extern struct Region *NewRegion();
struct Region *rgn; /* one region pointer */
struct Rectangle rect[14]; /* some rectangle structures */
struct Region *oldDamageList;
main()
{
SHORT x,y;
GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
if (GfxBase == NULL) exit(1);
LayersBase = (struct LayersBase *)OpenLibrary("layers.library",0);
if(LayersBase == NULL) exit(2);
InitLayers(&li);
InitView(&v);
v.ViewPort = &vp;
InitVPort(&vp);
vp.DWidth = WIDTH;
vp.DHeight = HEIGHT;
vp.RasInfo = &ri;
InitBitMap(&b,DEPTH,WIDTH,HEIGHT);
ri.BitMap = &b;
ri.RxOffset = 0;
ri.RyOffset = 0;
ri.Next = NULL;
cm = GetColorMap(4);
colorpalette = cm->ColorTable;
for(i=0; i<4; i++)
*colorpalette++ = colortable[i];
vp.ColorMap = cm;
for(i=0; i<DEPTH; i++)
{
b.Planes[i] = (PLANEPTR)AllocRaster(WIDTH,HEIGHT);
if(b.Planes[i] == NULL) exit(NOT_ENOUGH_MEMORY);
}
MakeVPort( &v, &vp );
MrgCop( &v );
for(i=0; i<2; i++)
{
displaymem = (UBYTE *)b.Planes[i];
for(j=0; j<RASSIZE(WIDTH,HEIGHT); j++)
*displaymem++ = 0;
/* zeros to all bytes of the display area */ }
LoadView(&v);
layer = CreateUpfrontLayer(&li,&b,0,0,200,140,FLAGS,NULL);
if(layer==NULL) exit(3);
rp = layer->rp;
SetAPen(rp,3);
RectFill(rp,0,0,199,139); /* show the layer itself */
j=10; /* initialize the rectangles */
for(i=0; i<10; i++)
{
rect[i].MinX = j;
rect[i].MaxX = j + 8;
rect[i].MinY = 20;
rect[i].MaxY = 120;
j += 16;
}
rgn = NewRegion(); /* get a new region to use */
if(rgn == NULL) exit(4);
for(i=0; i<14; i++)
OrRectRegion(rgn,&rect[i]);
oldDamageList = layer->DamageList;
layer->DamageList = rgn;
BeginUpdate(layer);
/* here insert the drawing routines to draw something
* behind the slats.
*/
x = 4; y = 10;
SetAPen(rp,0);
SetDrMd(rp,JAM1);
RectFill(rp,0,0,199,139);
SetAPen(rp,1);
SetBPen(rp,0);
SetDrMd(rp,JAM2);
for(i=0; i<14; i++)
{
Move(rp, x, y);
Text(rp,"Behind A Fence",14);
x += 4; y += 9;
}
EndUpdate(layer);
layer->DamageList = oldDamageList;
DisposeRegion(rgn);
FOREVER
; /* do nothing till user resets machine */
FreeMemory();
} /* end of main() */
FreeMemory()
{ /* return user and system-allocated memory to sys manager */
for(i=0; i<DEPTH; i++) /* free the drawing area */
FreeRaster(b.Planes[i],WIDTH,HEIGHT);
FreeColorMap(cm); /* free the color map */
/* free dynamically created structures */
FreeVPortCopLists(&vp);
FreeCprList(&v.LOFCprList);
return;
}